﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 150;
    private Rigidbody2D _rigidbody;
    private AudioSource _audiosource;

    // 加载脚本实例时调用 Awake
    private void Awake()
    {
        _rigidbody = GetComponent<Rigidbody2D>();
        _audiosource = GetComponent<AudioSource>();
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (_rigidbody == null)
        {
            return;
        }

        //上下移动
		if (Input.GetMouseButtonDown(0))
        {
            _rigidbody.velocity = new Vector2(0, speed);
            if (!GameServer.getSingleton().ismute)
            {
                _audiosource.Play();
            }
        }

        //小鸟朝向
        if (_rigidbody.velocity.y > 0)
        {
            transform.eulerAngles = new Vector3(0, 0, 60);
        }
        else
        {
            transform.eulerAngles = new Vector3(0, 0, -60);
        }
	}
}
